import { getBehaviourClassByName, getGameObjectById } from "../engine";
import { Behaviour } from "../engine/Behaviour";
import { BitmapRenderer } from "../engine/BitmapRenderer";
import { string } from "../engine/validators/string";
import { GameObjectAcitivable } from "./GameObjectAcitivable";
import { Sound } from "./sound";

export class D4Behaviour extends Behaviour {

    @string()
    source=""
    max=32
    scene=4

    onStart(): void{
        
        this.source=this.gameObject.getBehaviour(BitmapRenderer).source;

        let i=24;



        this.gameObject.onClick = (event) =>{
            
            if (this.gameObject.engine.mode === "play") {
                    if(i<=this.max){
                    i=i+1
                    this.source= "./assets/images/Scene4_dialogue_"+String(i)+".png"
                }
                    if(i==this.max+1)
                    {
                        const parent = this.gameObject.engine.rootGameObject;
                        const index = parent.children.length;
                        this.source= "./assets/images/fullempty.png"
                        parent.children.splice(0, index);
                        const SCENE = this.gameObject.engine.createPrefab('./assets/scenes/scene'+this.scene+'.yaml');
                        parent.addChild(SCENE);
                        const scene4=getGameObjectById('Scene4')
                        const sound=getBehaviourClassByName('Sound')
                        if(scene4){
                            if(sound.isOpen===true || sound.isOpen===undefined){
                                scene4.getBehaviour(Sound).play();
                            }
                        }
                    }   
        }
        }
    }
    onTick(duringTime: number) {
        this.gameObject.getBehaviour(BitmapRenderer).source = this.source; 
    }
    
}